from pysqlite2 import dbapi2 as sqlite
import pysqlite2

class temp_ver():
    def __init__(self, mid, name, passwd, status, access):
        self.mid = mid
        self.name = name
        self.passwd = passwd
        self.status = status
        self.access = access
    
    def verify(self):
        conn = sqlite.connect('temp.db')
        curs = conn.cursor()
        
        sql0 = '''DROP TABLE login'''
        sql1 = '''CREATE TABLE [login] (
          [id] BIGINT(100) NOT NULL ON CONFLICT ROLLBACK PRIMARY KEY, 
          [name] VARCHAR(100) NOT NULL ON CONFLICT ROLLBACK, 
          [password] VARCHAR(100) NOT NULL ON CONFLICT ROLLBACK, 
          [status] VARCHAR(2) NOT NULL ON CONFLICT ROLLBACK,
          [daccess] TEXT NOT NULL ON CONFLICT ROLLBACK)'''
        
        sql2 = 'INSERT INTO login VALUES(' + str(self.mid) + ",'" + str(self.name) + "','" + str(self.passwd) + "','" + str(self.status) + "','" +  str(self.access) + "')"
        #sql2 = 'INSERT INTO login VALUES(1,"kevin","blackid","1","2011-05-31 05:03:00")'
        sql3 = "SELECT * FROM login"
        
        try:
            curs.execute(sql1)
            conn.commit()
        except pysqlite2._sqlite.OperationalError, e:
            #curs.execute(sql0)
            #conn.commit()
            pass
        #try:
        #    curs.execute(sql2)
        #except pysqlite2._sqlite.OperationalError, e:
        #    curs.execute(sql1)
        #    curs.execute(sql2)
        #    conn.commit()
        
        curs.execute(sql3)
        conn.commit()    
        
        data = curs.fetchall()
        return data
        
        #for row in curs:         #for test only
        #    print row            #for test only
        
if __name__ == "__main__":        #for test only
    app = temp_ver(1,"kevin","blackid","1","2011-05-31 05:03:00")              #for test only
    print app.verify()            #for test only
            
            
            
            